package com.UBC417.termproject.Servlet;

import java.io.IOException;
import java.util.logging.Logger;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.UBC417.termproject.Data.Buyer;
import com.UBC417.termproject.Data.Comment;
import com.google.gson.Gson;

@SuppressWarnings("serial")
public class ViewSellerCommentServlet extends HttpServlet{
private static final Logger log = Logger.getLogger(SubscribeServlet.class.getName());
	
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws IOException, ServletException {
		
		HttpSession session = req.getSession();
		// Get parameters		
		String sellerId = req.getParameter("sellerId");
		if (sellerId==null){
			sellerId=(String)session.getAttribute("id");
		}
		log.info("sellerId: "+ sellerId);
		
		//TODO:get user rating+ comments
		List<Comment> comments = Buyer.GetComment(sellerId);
		double rating= Buyer.GetRating(sellerId);
		log.info("rating: "+ rating);
		log.info("comment: "+ new Gson().toJson(comments));
		//TODO: writes response as JSON
	    resp.setContentType("text/plain");
	    resp.setCharacterEncoding("UTF-8");
	    resp.getWriter().write(new Gson().toJson(comments));
				
	}

}
